package rabbit.util;


import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * Created with IntelliJ IDEA.
 * ClassName: RabbitMQUtils
 * Package: rabbit.util
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-10-25
 * Time: 15:25
 */

//连接工厂创建信道的工具类

public class RabbitMqUtils {
    //重复方法的抽取
    public static Channel getChanel() throws IOException, TimeoutException {

        //创建一个连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("hadoop100");
        factory.setUsername("admin");
        factory.setPassword("123");
        //通过连接工厂创建连接
        Connection connection = factory.newConnection();
        //通过连接获取信道
        Channel channel = connection.createChannel();

        return channel;
    }

}
